/*
 * HomePagerAdapter.java
 * business
 *
 * Created by ChenTao on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.yidiandao.business.R;
import com.yidiandao.business.ui.main.home.HomeFragment;
import com.yidiandao.business.ui.shop.ShopFragment;
import com.yidiandao.business.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;

/** 首页 多个Fragment的PagerAdapter. */
public class HomePagerAdapter extends FragmentStatePagerAdapter {

    private List<Fragment> mFragments;
    private String[] mTitles;

    public HomePagerAdapter(FragmentManager fm) {
        super(fm);

        // 添加两个页面
        mFragments = new ArrayList<>();
        mFragments.add(HomeFragment.getInstance());
        mFragments.add(ShopFragment.getInstance());

        mTitles = UIUtils.getStringArray(R.array.home_title);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mTitles[position];
    }
}
